package lu.med.praxiswahl.wahlumed.client.mahnungen;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class MahnungenTableSelectionListener implements ListSelectionListener
{
    private MahnungenTableModel tableModel;

    public MahnungenTableSelectionListener(MahnungenTableModel tableModel)
    {
	this.tableModel = tableModel;
    }

    public void valueChanged(ListSelectionEvent e)
    {
	if (e.getValueIsAdjusting())
	    return;

	ListSelectionModel lsm = (ListSelectionModel) e.getSource();
	if (lsm.isSelectionEmpty())
	{
	    tableModel.setSelected(-1);
	}
	else
	{
	    int selectedRow = lsm.getMinSelectionIndex();
	    tableModel.setSelected(selectedRow);
	}
    }
}